<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户数据权限列表')" />
    <style>
        .layui-table-click {
            background-color:#1E9FFF;
            color:#fff;
        }
    </style>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
                <div class="col-sm-12 select-table table-striped">
                    <div class="col-sm-3">
                    <table id="bootstrap-table"></table>
                    </div>
                    <div class="col-sm-9">
                        <form id="user-form">
                            <div class="select-list">
                                <ul>
                                    <li>
                                        数据类型：<select id="sdDataauthType" name="sdDataauthType" th:with="type=${@baseSd.getItem('user_dataauth_type')}" onchange="queryUserDataauth()">
                                        <option th:each="item : ${type}" th:text="${item.na}" th:value="${item.cd}"></option>
                                    </select>
                                    </li>
                                    <li>
                                        <a class="btn btn-primary btn-rounded btn-sm" onclick="openDesign()"><i class="fa fa-search"></i>&nbsp;分配</a>
                                    </li>
                                </ul>
                            </div>
                        </form>
                       <table id="mainTable"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/dataauth";
        var G_USERID="";
        function openDesign(){
            var tableName = $("#sdDataauthType").val();
            var des = $("#sdDataauthType").text();
            //$.modal.open("["+des+"]数据",prefix+"/dimData?cd="+tableName+"&userId="+$("#userId").val(),900,600);
            var options = {
                title:"["+des+"]数据",
                width: "900",
                height: "600",
                url: prefix+"/dimData?cd="+tableName+"&userId="+G_USERID,
                callBack: callBack
            };
            $.modal.openOptions(options);
        }
        function callBack(index, layero) {
            var iframeWin = layero.find('iframe')[0];
            iframeWin.contentWindow.submitHandler(index, layero);
            queryUserDataauth();
        }
        function remove(id,name) {
            $.modal.confirm("确定要删除[" + name + "]吗？", function() {
                $.ajax({
                    url: prefix + "/remove?ids="+id,
                    cache: false,
                    type: 'POST',
                    dataType: 'json',
                    success: function (result) {
                        if(result.code==0) {
                            queryUserDataauth();
                        }
                    }
                });
            });
        }
        function queryUserDataauth() {

            $("#mainTable").bootstrapTable('destroy');
            $('#mainTable').bootstrapTable({
                url: prefix+"/prefix",
                queryParams: function (params) {
                    return {"userId":G_USERID,"sdDataauthType":$("#sdDataauthType").val()}
                },
                method:"post",
                removeUrl: prefix + "/remove",
                modalName: "用户数据权限",
                columns: [
                    {
                        field: 'dataauthId',
                        title: '主键',
                        visible: false
                    },
                    {
                        field: 'dataauthCd',
                        title: '编码'
                    },
                    {
                        field: 'dataauthName',
                        title: '名称'
                    },
                    {
                        field: 'naEmpCre',
                        title: '添加人'
                    },
                    {
                        field: 'dtSysCre',
                        title: '添加时间'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="remove(\'' + row.dataauthId + '\',\''+row.dataauthName+'\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                    }]
            });
        }
        $(function() {
            var options = {
                url: "/system/user/list",
                method:"post",
                modalName: "定时任务",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                search: true,
                showRefresh : true,
                columns: [
                    {
                        field: 'userId',
                        title: '用户ID',
                        visible: false
                    },
                    {
                        field: 'loginName',
                        title: '登录名称',
                        sortable: true
                    },
                    {
                        field: 'userName',
                        title: '用户名称'
                    }],
                onClickRow: onClickRow,
                onSearch:search
            };
            $.table.init(options);
            function onClickRow(row, $element) {
                $element.addClass('layui-table-click').siblings().removeClass('layui-table-click');
                G_USERID = row.userId;
                queryUserDataauth();
            }
            function search(row, $element){
                alert("hello");
            }


        });
    </script>
</body>
</html>